
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--导入js库--%>
<script src="${pageContext.request.contextPath}/jsp/jquery-3.4.1.min.js"></script>
<html>
<head>
    <title>登录界面</title>
</head>
<body>
    <form  id="login" method="post">
        用户名:<input type="text" placeholder="请输入用户名" name="username"><br/>
        密&ensp;&ensp;码<input type="text" placeholder="请输入密码" name="password"><br/>
        <input type="button"  id="myLogin" value="登录" >
        <input type="button" id="myregister" value="注册" onclick="jump()">
    </form>

</body>
        <script type="text/javascript">
            function jump() {
                window.location.href="/SSM_war/user/adminregister";
            }
        </script>
        <script>
          $(function(){
              //alert("页面载入时间触发了")
             $("#myLogin").click(function(){
                 //发送异步请求
                 $.ajax({
                     //后台接口地址
                     url:"/SSM_war/user/login",
                     //请求的数据
                     data:$("#login").serialize(),

                     //提交方式
                     type:"post",
                     //响应成功的回调函数
                     success:function (data) {
                         alert(data);
                         if (data.code==1){
                             alert(data.msg);
                            window.location.href="/SSM_war/shop/findAll"
                         }
                         if (data.code == 0) {
                             alert(data.msg)
                         }
                     },
                     error:function (data) {

                     },
                     dataType:"json"
                 });
             });
          });
        </script>
</html>
